//
//  XMAddressBookView.m
//  XMJJ_zml
//
//  Created by apple on 2025/5/13.
//

#import "XMAddressBookView.h"
#import "XMAddFriendCell.h"

@interface XMAddressBookView ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tbl;

@property (nonatomic, strong) NSArray *userModelArr;

@end

@implementation XMAddressBookView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.navView];
    self.navView.backgroundColor = kColorHEX(0xF6F6F6);
    self.navTitleLabel.text = @"通讯录好友";
    
    [self addSubview:self.tbl];
}

- (void)setContentWithUserModelArr:(NSArray *)userModelArr {
    _userModelArr = userModelArr;
    [_tbl reloadData];
}

#pragma mark - Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _userModelArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return KScaleWidth(77.0);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    XMAddFriendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XMAddFriendCellName" forIndexPath:indexPath];
    [cell setContentWithFriendModel:_userModelArr[indexPath.row]];
    return cell;
}

#pragma mark - Init
- (UITableView *)tbl {
    if (!_tbl) {
        _tbl = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavagationBarH, self.width, self.height - kNavagationBarH)];
        _tbl.delegate = self;
        _tbl.dataSource = self;
        [_tbl registerClass:[XMAddFriendCell class] forCellReuseIdentifier:@"XMAddFriendCellName"];
        if (@available(iOS 15.0, *)) {
            _tbl.sectionHeaderTopPadding = 0;
        } else {
            _tbl.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            // Fallback on earlier versions
        }
    }
    return _tbl;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
